package server.util.tickevents;

import adventure.room.RoomManager;
import server.util.Broadcaster;

/**
 *
 * @author Michael Hanns
 *
 */
public class CleanupRooms implements TickerEvent {
    
    private Broadcaster broadcaster;
    private RoomManager rooms;
    
    public CleanupRooms(Broadcaster b, RoomManager r) {
        this.broadcaster = b;
        this.rooms = r;
    }
    
    @Override
    public void executeEvent() {
        decayEmptyCorpses();
    }
    
    private void decayEmptyCorpses() {
        System.out.println("Decaying...");
        for (int x = 0; x < 100; x++) {
            for (int y = 0; y < 100; y++) {
                for (int z = 0; z < 100; z++) {
                    if (rooms.roomExists(x, y, z)) {
                        String text = rooms.decayCorpses(x, y, z);
                        if(text.length() > 0) {
                            broadcaster.broadcastToRoom(x, y, z, text);
                        }
                        
                        text = rooms.decayTempItems(x, y, z);
                        System.out.println(text.length() + "////" + text);
                        
                        if(text.length() > 0) {
                            broadcaster.broadcastToRoom(x, y, z, text);
                        }
                    }
                }
            }
        }
    }
    
}
